package ch.simas.cdi;

import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;

/**
 *
 * @author Simon
 */
@Interceptor
@Traceable
public class LogInterceptor implements Serializable {

    private static final Logger LOGGER = Logger.getLogger(LogInterceptor.class.toString());
    
    @AroundInvoke
    public Object log(InvocationContext ic) throws Exception {
        try {
            LOGGER.log(Level.INFO, "Before: {0}", ic.getMethod().getName());

            return ic.proceed();

        } finally {
            LOGGER.log(Level.INFO, "After:  {0}", ic.getMethod().getName());
        }
    }
}
